#include "customemployeewidget.h"
#include "ui_customemployeewidget.h"

CustomEmployeewidget::CustomEmployeewidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::CustomEmployeewidget)
{
    ui->setupUi(this);
    connect(this, &CustomEmployeewidget::sendRemoveItem, qobject_cast<EmployeePage*>(parent), &EmployeePage::updateEmployee);
    connect(ui->pushButton, &QPushButton::clicked, this, &CustomEmployeewidget::on_pushButton_clicked);
    //connect(this, &CustomEmployeewidget::showEditPage, &employeePage, &EmployeePage::on_AddEmployeeButton_clicked);
}

void CustomEmployeewidget::setText(const QString &name, const QString &surname, const QString &patronymic, const QString &number, const QString &role, const QByteArray &image)
{
    QPixmap p;
    ui->Name->setText(name);
    ui->Surname->setText(surname);
    ui->Patronymic->setText(patronymic);
    ui->Number->setText(number);
    ui->Role->setText(role);
    if(p.loadFromData(image, "JPEG"))
    {
        ui->Image->setPixmap(p);
    }
}

QString CustomEmployeewidget::getText()
{
    return ui->Name->text();
}

CustomEmployeewidget::~CustomEmployeewidget()
{
    delete ui;
}

void CustomEmployeewidget::on_pushButton_clicked()
{
    emit sendRemoveItem(ui->Name->text(), ui->Surname->text(), ui->Patronymic->text(), ui->Number->text(), ui->Role->text());
    emit showEditPage();
}

